package com.example.user.service;


import com.example.common.entity.ResultDO;
import com.example.common.User;
import com.example.common.util.JwtUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @program: microservice
 * @description:
 * @author: meihua
 * @created: 2020/11/16 16:15
 */
@Service
public class UserService {

    @Value("${user.name}")
    public String name;
    @Value("${user.password}")
    public String passWord;

    private static final String loginErrorMsg="用户名或密码错误";

    public User getUser(Integer id){
//        if(Math.random()*10<2){
//            //模拟处理时间
//            Method(500);
//        }
      //  Method(500);
        return new User("王五",id);
    }

    public ResultDO login(String name, String passWord){
        if (this.passWord.equals(passWord)&&this.name.equals(name)){
            return  new  ResultDO(JwtUtil.createJWT(UUID.randomUUID().toString(),name, null));
        }
        return new  ResultDO(false,loginErrorMsg);
    }



    void Method(Integer time){
        try {
            Thread.sleep(time);
        }catch (InterruptedException e){
            e.printStackTrace();
        }finally {
        }
    }

}
